﻿Imports BUS
Imports DTO
Public Class BangDiemMonHoc

    Private Sub btnthoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnthoat.Click
        Me.Close()
    End Sub

    Private Sub BangDiemMonHoc_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim _buslop As New ClopBUS()
        cbblop.DataSource = _buslop.LayDanhSachLop()
        cbblop.DisplayMember = "TenLop"
        cbblop.ValueMember = "MaLop"
        Dim _busmon As New CMonHocBUS()
        cbbmon.DataSource = _busmon.LayDanhSachMonHoc()
        cbbmon.DisplayMember = "TenMonHoc"
        cbbmon.ValueMember = "MaMonHoc"
        Dim _bushk As New CHocKyBUS()
        cbbhocky.DataSource = _bushk.LayDanhSachHK()
        cbbhocky.DisplayMember = "TenHocKy"
    End Sub

    Dim _DMHdto As New CDiemMonHocDTO()
    Private Sub btnxem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnxem.Click
        Dim _lopdto As New CLopDTO()
        _lopdto = cbblop.SelectedItem
        Dim _Monhocdto As New CMonHocDTO()
        _Monhocdto = cbbmon.SelectedItem
        Dim _HKdto As New CHocKyDTO()
        _HKdto = cbbhocky.SelectedItem
        _DMHdto.MaLop = _lopdto.MaLop
        _DMHdto.MaMonHoc = _Monhocdto.MaMonHoc
        _DMHdto.TenHocKy = _HKdto.TenHocKy
        Dim _busctdmh As New CChiTietDiemMonHocBUS()
        Dim _ds As New List(Of CChiTietDiemMonHocCRT)
        _ds = _busctdmh.XemDuLieu(_DMHdto)
        dtgvdschitietdiem.Rows.Clear()
        Dim i As Integer
        For i = 0 To _ds.Count - 1
            dtgvdschitietdiem.Rows.Add(i + 1, _ds(i).MaChiTietDiemMonHoc, _ds(i).MaHocSinh, _ds(i).HoTen, _ds(i).Diem15, _ds(i).Diem1Tiet, _ds(i).DiemCuoiHocKy, _ds(i).MaDiemMonHoc)
        Next

    End Sub

    Private Sub btnghidiem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnghidiem.Click
        Try
            Dim _dtt As New DataTable()
            Dim _busctdmh As New CChiTietDiemMonHocBUS()
            _dtt = _busctdmh.LayDanhSachCTDMonHoc(_DMHdto)
            Dim i As Integer
            For i = 0 To dtgvdschitietdiem.Rows.Count - 2
                _dtt.Rows(i)("Diem15") = Single.Parse(dtgvdschitietdiem.Rows(i).Cells("cldiem15").Value)
                _dtt.Rows(i)("Diem1Tiet") = Single.Parse(dtgvdschitietdiem.Rows(i).Cells("cldiem1tiet").Value)
                _dtt.Rows(i)("DiemCuoiHocKy") = Single.Parse(dtgvdschitietdiem.Rows(i).Cells("cldiemcuoihocky").Value)
            Next

            If _busctdmh.CapNhatChiTietDiemMonHoc(_dtt) > 0 Then
                MessageBox.Show("Ghi Diem Thanh Cong")
            Else
                MessageBox.Show("Ghi Diem That Bai")
            End If
        Catch ex As Exception
            MessageBox.Show("Loi --> " + ex.ToString())
        End Try
        
    End Sub
End Class